package cn.zd.erp.auth.dep.service.ebo;

import java.util.ArrayList;
import java.util.List;






import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.zd.erp.auth.dep.dao.dao.OrgDao;
import cn.zd.erp.auth.dep.service.ebi.Orgebi;
import cn.zd.erp.auth.dep.vo.Torganization1;
import cn.zd.erp.util.base.Organization;
import cn.zd.erp.util.base.Tree;
@Service
public class Orgebo implements Orgebi {
	@Autowired
	private OrgDao orgDao;

	public List<Torganization1> getAll() {
		// TODO Auto-generated method stub
		return null;
	}

	public void sava(Torganization1 torganization) {
		// TODO Auto-generated method stub
		orgDao.sava(torganization);
	}

	public List<Tree> getAllOrg() {
		List<Tree> lt = new ArrayList<>();
		List<Torganization1> l = orgDao.getAllOrg();
		
		if ((l != null) && (l.size() > 0)) {
			for (Torganization1 r : l) {
				Tree tree = new Tree();
				tree.setId(r.getId().toString());
				if (r.getOrganization() != null) {
					tree.setPid(r.getOrganization().getId().toString());
				}
				tree.setText(r.getName());
				tree.setIconCls(r.getIcon());
				lt.add(tree);
			}
		}
		return lt;

	}

	public List<Organization> treeGrid() {
		List<Organization> lr = new ArrayList<>();
		List<Torganization1> l = orgDao.getAllOrg();
		if ((l != null) && (l.size() > 0)) {
			for (Torganization1 t : l) {
				Organization r = new Organization();
				BeanUtils.copyProperties(t, r);
				if (t.getOrganization() != null) {
					r.setPid(t.getOrganization().getId());
					r.setPname(t.getOrganization().getName());
				}
				r.setIconCls(t.getIcon());
				lr.add(r);
			}
		}
		return lr;
	}

	public void delete(Torganization1 torganization) {
		orgDao.delete(torganization);
	}


	public Torganization1 getOrgById(Long id) {
		return orgDao.getOrgById(id);
	}
}